import ExcelJS from 'exceljs';
import FileSaver from 'file-saver';

/**
 * 下载文件excel
 * @param workbook ExcelJS.Workbook()实例对象
 * @param fileName 下载文件名
 */
export const downExcelJsFile = (workbook: ExcelJS.Workbook, fileName?: string) => {
  return new Promise((resolve) => {
    workbook.xlsx.writeBuffer().then(async (buffer) => {
      await FileSaver.saveAs(
        new Blob([buffer], { type: 'application/octet-stream' }),
        fileName || `test.xlsx`,
      );
      resolve(null);
    });
  });
};
